package com.ag.lzw.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.ag.bean.TbTaskStatus;
import com.ag.dao.TbTaskStatusDAO;

/**
 * 任务办结状态的DAO类
 * @author zhiweiofli
 *
 */
@Repository("overStatusDAO")
public class TbOverStatusDAO  extends HibernateDaoSupport{
	
	@Autowired
	public void init(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	private static final Log log = LogFactory.getLog(TbTaskStatusDAO.class);
	
	public void save(TbTaskStatus transientInstance) {
		log.debug("saving TbOverStatus instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbTaskStatus persistentInstance) {
		log.debug("deleting TbOverStatus instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbTaskStatus findById(java.lang.String id) {
		log.debug("getting TbOverStatus instance with id: " + id);
		try {
			TbTaskStatus instance = (TbTaskStatus) getHibernateTemplate().get(
					"com.ag.lzw.common.TbOverStatus", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public void attachDirty(TbTaskStatus instance) {
		log.debug("attaching dirty TbOverStatus instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbTaskStatus instance) {
		log.debug("attaching clean TbOverStatus instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbTaskStatusDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TbTaskStatusDAO) ctx.getBean("TbOverStatusDAO");
	}

}
